import pandas as pd
import os

curPath = os.path.abspath(os.path.dirname(__file__))


def readCsv():
    csv_paths = curPath + "/raw_data/"
    faqs = []
    if os.path.isdir(csv_paths):
        for file in os.listdir(csv_paths):
            if not file.endswith('.csv'):
                continue
            df = pd.read_csv(csv_paths + file)
            faqDictList = df.to_dict('records')

            faqs.extend(faqDictList)
    else:
        df = pd.read_csv(csv_paths)
        faqDictList = df.to_dict('records')

        faqs.extend(faqDictList)


    return faqs


def read_map():
    res = readCsv()
    map = {}
    for r in res:
        map[r['录音编号']] = {'话术': r.get('用户疑义解答')}
        action = r.get('动作标签')
        if action and isinstance(action, str):
            map[r['录音编号']]['动作标签'] = action
    return map


if __name__ == '__main__':
    res = read_map()
    print(res['F21'].get('动作标签'))
